﻿package mortal.game.view.copy.expCopy
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.copy.*;
    import mortal.mvc.core.*;

    public class ExpCopyRightInfoWin extends CopyInfoPanelBase
    {
        private var _expNumTxt:BitmapNumberText;
        private var _bgImg:GImageBitmap;
        private var _hurtNumTxt:BitmapNumberText;
        private var _doubleCountDown:SecTimerBitmapView;
        private var _baseItem:BaseItem;
        private var _itemName:GTextFiled;
        private var _autoFightBtn:GLoadingButton;
        private var _leaveCopyBtn:GLoadingButton;
        private static var _instance:ExpCopyRightInfoWin;

        public function ExpCopyRightInfoWin()
        {
            super(ImagesConst.copyInfoPanelTitle_expCopy, 262, 467);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bgImg = UIFactory.gImageBitmap(ImagesConst.ExpCopyInfoBg, 0, -3, _bodySprite);
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35220), 50, 122, 220, 20, _bodySprite, GlobalStyle.textFormatLv));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35221), 36, 155, 220, 80, _bodySprite, GlobalStyle.textFormatDanLan, true));
            pushUIToDisposeVec(UIFactory.bg(32, 292, 200, 2, this, ImagesConst.SplitLine));
            this._hurtNumTxt = UIFactory.bitmapNumberText(112, 55, "ExpCopyTimesNum.png", 20, 27, -8, _bodySprite, 13, BitmapNumberText.Left);
            this._expNumTxt = UIFactory.bitmapNumberText(112, 90, "ExpCopyTimesNum.png", 20, 27, -8, _bodySprite, 13, BitmapNumberText.Left);
            this._doubleCountDown = UIFactory.secTimerBitmapView(44, 315, "ChallengeTimerNum.png", 35, 48, 0, _bodySprite, 10);
            this._doubleCountDown.customCharIndex = {0:0, 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, ::10};
            this._doubleCountDown.setParse("mm:ss");
            this._baseItem = UICompomentPool.getUICompoment(BaseItem);
            this._baseItem.setItemStyle();
            this._baseItem.itemData = new ItemData(GameConst.TConstExpCopyItemCode);
            this._baseItem.move(39, 238);
            _bodySprite.addChild(this._baseItem);
            this._itemName = UIFactory.gTextField("", this._baseItem.x + 50, this._baseItem.y + 2, 150, 50, _bodySprite, GlobalStyle.textFormatDanLan);
            this._itemName.htmlText = this._baseItem.itemData.itemInfo.htmlName + Language.getString(35222);
            this._autoFightBtn = UIFactory.gLoadingButton(ResFileConst.autoFightBtn, 20, 399, 103, 38, _bodySprite);
            this._autoFightBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._leaveCopyBtn = UIFactory.gLoadingButton(ResFileConst.leaveCopyBtn, 140, 399, 103, 38, _bodySprite);
            this._leaveCopyBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._itemName.dispose(param1);
            this._itemName = null;
            this._bgImg.dispose(param1);
            this._bgImg = null;
            this._expNumTxt.dispose(param1);
            this._expNumTxt = null;
            this._hurtNumTxt.dispose(param1);
            this._hurtNumTxt = null;
            this._doubleCountDown.dispose(param1);
            this._doubleCountDown = null;
            this._autoFightBtn.dispose(param1);
            this._autoFightBtn = null;
            this._leaveCopyBtn.dispose(param1);
            this._leaveCopyBtn = null;
            this._baseItem.dispose(param1);
            this._baseItem = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            if (event.target == this._leaveCopyBtn)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyClickQuickBtn));
            }
            else if (event.target == this._autoFightBtn)
            {
                AIManager.cancelAll();
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoFight_A));
            }
            return;
        }// end function

        public function updateInfo(param1:SExpCopyHurtInfo) : void
        {
            this._hurtNumTxt.addToValue(param1.hurt);
            this._expNumTxt.addToValue(param1.exp);
            this._doubleCountDown.setLeftTime(param1.second);
            return;
        }// end function

        public static function get instance() : ExpCopyRightInfoWin
        {
            if (_instance == null)
            {
                _instance = new ExpCopyRightInfoWin;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
